package com.zhz.mall.portal.modules.ums.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zhz.mall.portal.modules.ums.mapper.UmsMemberReceiveAddressMapper;
import com.zhz.mall.portal.modules.ums.model.UmsMemberReceiveAddress;
import com.zhz.mall.portal.modules.ums.service.UmsMemberReceiveAddressService;
import com.zhz.mall.portal.modules.ums.service.UmsMemberService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 会员收货地址表 服务实现类
 * </p>
 *
 * @author zhouhengzhe
 * @since 2023-02-04
 */
@Service
public class UmsMemberReceiveAddressServiceImpl extends ServiceImpl<UmsMemberReceiveAddressMapper, UmsMemberReceiveAddress> implements UmsMemberReceiveAddressService {

    @Autowired
    private UmsMemberService umsMemberService;

    /**
     * 添加用户地址
     *
     * @param address
     * @return
     */
    @Override
    public Boolean add(UmsMemberReceiveAddress address) {
        Long currentMemberId = umsMemberService.getCurrentMember().getId();
        address.setMemberId(currentMemberId);
        return this.save(address);
    }

    /**
     * 通过id更新用户地址
     *
     * @param address
     * @return
     */
    @Override
    public Boolean edit(UmsMemberReceiveAddress address) {
        return this.updateById(address);
    }

    /**
     * 根据id删除收件地址
     *
     * @param id
     * @return
     */
    @Override
    public Boolean delete(Long id) {
        return this.removeById(id);
    }

    /**
     * 获取当前用户地址信息
     *
     * @return
     */
    @Override
    public List<UmsMemberReceiveAddress> listByMemberId() {
        QueryWrapper<UmsMemberReceiveAddress> queryWrapper = new QueryWrapper<>();
        queryWrapper.lambda()
                .eq(UmsMemberReceiveAddress::getMemberId, umsMemberService.getCurrentMember().getId());
        return this.list(queryWrapper);
    }
}
